package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSms;
import com.ruoyi.system.service.ISysSmsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日程任务Controller
 * 
 * @author ruoyi
 * @date 2021-11-10
 */
@Controller
@RequestMapping("/system/sms")
public class SysSmsController extends BaseController
{
    private String prefix = "system/sms";

    @Autowired
    private ISysSmsService sysSmsService;

    @RequiresPermissions("system:sms:view")
    @GetMapping()
    public String sms()
    {
        return prefix + "/sms";
    }

    /**
     * 查询日程任务列表
     */
    @RequiresPermissions("system:sms:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysSms sysSms)
    {
        startPage();
        List<SysSms> list = sysSmsService.selectSysSmsList(sysSms);
        return getDataTable(list);
    }

    /**
     * 导出日程任务列表
     */
    @RequiresPermissions("system:sms:export")
    @Log(title = "日程任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysSms sysSms)
    {
        List<SysSms> list = sysSmsService.selectSysSmsList(sysSms);
        ExcelUtil<SysSms> util = new ExcelUtil<SysSms>(SysSms.class);
        return util.exportExcel(list, "sms");
    }

    /**
     * 新增日程任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存日程任务
     */
    @RequiresPermissions("system:sms:add")
    @Log(title = "日程任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysSms sysSms)
    {
        sysSms.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(sysSmsService.insertSysSms(sysSms));
    }

    /**
     * 修改日程任务
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysSms sysSms = sysSmsService.selectSysSmsById(id);
        mmap.put("sysSms", sysSms);
        return prefix + "/edit";
    }

    /**
     * 修改保存日程任务
     */
    @RequiresPermissions("system:sms:edit")
    @Log(title = "日程任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysSms sysSms)
    {
        return toAjax(sysSmsService.updateSysSms(sysSms));
    }

    /**
     * 删除日程任务
     */
    @RequiresPermissions("system:sms:remove")
    @Log(title = "日程任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysSmsService.deleteSysSmsByIds(ids));
    }
}
